// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Ingest;

public sealed partial class DateIndexNameProcessor
{
	/// <summary>
	/// <para>An array of the expected date formats for parsing dates / timestamps in the document being preprocessed.<br/>Can be a java time pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("date_formats")]
	public ICollection<string> DateFormats { get; set; }

	/// <summary>
	/// <para>How to round the date when formatting the date into the index name. Valid values are:<br/>`y` (year), `M` (month), `w` (week), `d` (day), `h` (hour), `m` (minute) and `s` (second).<br/>Supports template snippets.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("date_rounding")]
	public string DateRounding { get; set; }

	/// <summary>
	/// <para>Description of the processor.<br/>Useful for describing the purpose of the processor or its configuration.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("description")]
	public string? Description { get; set; }

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Serverless.Field Field { get; set; }

	/// <summary>
	/// <para>Conditionally execute the processor.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("if")]
	public string? If { get; set; }

	/// <summary>
	/// <para>Ignore failures for the processor.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("ignore_failure")]
	public bool? IgnoreFailure { get; set; }

	/// <summary>
	/// <para>The format to be used when printing the parsed date into the index name.<br/>A valid java time pattern is expected here.<br/>Supports template snippets.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("index_name_format")]
	public string? IndexNameFormat { get; set; }

	/// <summary>
	/// <para>A prefix of the index name to be prepended before the printed date.<br/>Supports template snippets.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("index_name_prefix")]
	public string? IndexNamePrefix { get; set; }

	/// <summary>
	/// <para>The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("locale")]
	public string? Locale { get; set; }

	/// <summary>
	/// <para>Handle failures for the processor.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("on_failure")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor>? OnFailure { get; set; }

	/// <summary>
	/// <para>Identifier for the processor.<br/>Useful for debugging and metrics.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("tag")]
	public string? Tag { get; set; }

	/// <summary>
	/// <para>The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("timezone")]
	public string? Timezone { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor(DateIndexNameProcessor dateIndexNameProcessor) => Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor.DateIndexName(dateIndexNameProcessor);
}

public sealed partial class DateIndexNameProcessorDescriptor<TDocument> : SerializableDescriptor<DateIndexNameProcessorDescriptor<TDocument>>
{
	internal DateIndexNameProcessorDescriptor(Action<DateIndexNameProcessorDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DateIndexNameProcessorDescriptor() : base()
	{
	}

	private ICollection<string> DateFormatsValue { get; set; }
	private string DateRoundingValue { get; set; }
	private string? DescriptionValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private string? IfValue { get; set; }
	private bool? IgnoreFailureValue { get; set; }
	private string? IndexNameFormatValue { get; set; }
	private string? IndexNamePrefixValue { get; set; }
	private string? LocaleValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor>? OnFailureValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument> OnFailureDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument>> OnFailureDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument>>[] OnFailureDescriptorActions { get; set; }
	private string? TagValue { get; set; }
	private string? TimezoneValue { get; set; }

	/// <summary>
	/// <para>An array of the expected date formats for parsing dates / timestamps in the document being preprocessed.<br/>Can be a java time pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> DateFormats(ICollection<string> dateFormats)
	{
		DateFormatsValue = dateFormats;
		return Self;
	}

	/// <summary>
	/// <para>How to round the date when formatting the date into the index name. Valid values are:<br/>`y` (year), `M` (month), `w` (week), `d` (day), `h` (hour), `m` (minute) and `s` (second).<br/>Supports template snippets.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> DateRounding(string dateRounding)
	{
		DateRoundingValue = dateRounding;
		return Self;
	}

	/// <summary>
	/// <para>Description of the processor.<br/>Useful for describing the purpose of the processor or its configuration.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Description(string? description)
	{
		DescriptionValue = description;
		return Self;
	}

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>Conditionally execute the processor.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> If(string? value)
	{
		IfValue = value;
		return Self;
	}

	/// <summary>
	/// <para>Ignore failures for the processor.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> IgnoreFailure(bool? ignoreFailure = true)
	{
		IgnoreFailureValue = ignoreFailure;
		return Self;
	}

	/// <summary>
	/// <para>The format to be used when printing the parsed date into the index name.<br/>A valid java time pattern is expected here.<br/>Supports template snippets.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> IndexNameFormat(string? indexNameFormat)
	{
		IndexNameFormatValue = indexNameFormat;
		return Self;
	}

	/// <summary>
	/// <para>A prefix of the index name to be prepended before the printed date.<br/>Supports template snippets.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> IndexNamePrefix(string? indexNamePrefix)
	{
		IndexNamePrefixValue = indexNamePrefix;
		return Self;
	}

	/// <summary>
	/// <para>The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Locale(string? locale)
	{
		LocaleValue = locale;
		return Self;
	}

	/// <summary>
	/// <para>Handle failures for the processor.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> OnFailure(ICollection<Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor>? onFailure)
	{
		OnFailureDescriptor = null;
		OnFailureDescriptorAction = null;
		OnFailureDescriptorActions = null;
		OnFailureValue = onFailure;
		return Self;
	}

	public DateIndexNameProcessorDescriptor<TDocument> OnFailure(Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument> descriptor)
	{
		OnFailureValue = null;
		OnFailureDescriptorAction = null;
		OnFailureDescriptorActions = null;
		OnFailureDescriptor = descriptor;
		return Self;
	}

	public DateIndexNameProcessorDescriptor<TDocument> OnFailure(Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument>> configure)
	{
		OnFailureValue = null;
		OnFailureDescriptor = null;
		OnFailureDescriptorActions = null;
		OnFailureDescriptorAction = configure;
		return Self;
	}

	public DateIndexNameProcessorDescriptor<TDocument> OnFailure(params Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument>>[] configure)
	{
		OnFailureValue = null;
		OnFailureDescriptor = null;
		OnFailureDescriptorAction = null;
		OnFailureDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>Identifier for the processor.<br/>Useful for debugging and metrics.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Tag(string? tag)
	{
		TagValue = tag;
		return Self;
	}

	/// <summary>
	/// <para>The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor<TDocument> Timezone(string? timezone)
	{
		TimezoneValue = timezone;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("date_formats");
		JsonSerializer.Serialize(writer, DateFormatsValue, options);
		writer.WritePropertyName("date_rounding");
		writer.WriteStringValue(DateRoundingValue);
		if (!string.IsNullOrEmpty(DescriptionValue))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(DescriptionValue);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (!string.IsNullOrEmpty(IfValue))
		{
			writer.WritePropertyName("if");
			writer.WriteStringValue(IfValue);
		}

		if (IgnoreFailureValue.HasValue)
		{
			writer.WritePropertyName("ignore_failure");
			writer.WriteBooleanValue(IgnoreFailureValue.Value);
		}

		if (!string.IsNullOrEmpty(IndexNameFormatValue))
		{
			writer.WritePropertyName("index_name_format");
			writer.WriteStringValue(IndexNameFormatValue);
		}

		if (!string.IsNullOrEmpty(IndexNamePrefixValue))
		{
			writer.WritePropertyName("index_name_prefix");
			writer.WriteStringValue(IndexNamePrefixValue);
		}

		if (!string.IsNullOrEmpty(LocaleValue))
		{
			writer.WritePropertyName("locale");
			writer.WriteStringValue(LocaleValue);
		}

		if (OnFailureDescriptor is not null)
		{
			writer.WritePropertyName("on_failure");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, OnFailureDescriptor, options);
			writer.WriteEndArray();
		}
		else if (OnFailureDescriptorAction is not null)
		{
			writer.WritePropertyName("on_failure");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument>(OnFailureDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (OnFailureDescriptorActions is not null)
		{
			writer.WritePropertyName("on_failure");
			writer.WriteStartArray();
			foreach (var action in OnFailureDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor<TDocument>(action), options);
			}

			writer.WriteEndArray();
		}
		else if (OnFailureValue is not null)
		{
			writer.WritePropertyName("on_failure");
			JsonSerializer.Serialize(writer, OnFailureValue, options);
		}

		if (!string.IsNullOrEmpty(TagValue))
		{
			writer.WritePropertyName("tag");
			writer.WriteStringValue(TagValue);
		}

		if (!string.IsNullOrEmpty(TimezoneValue))
		{
			writer.WritePropertyName("timezone");
			writer.WriteStringValue(TimezoneValue);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class DateIndexNameProcessorDescriptor : SerializableDescriptor<DateIndexNameProcessorDescriptor>
{
	internal DateIndexNameProcessorDescriptor(Action<DateIndexNameProcessorDescriptor> configure) => configure.Invoke(this);

	public DateIndexNameProcessorDescriptor() : base()
	{
	}

	private ICollection<string> DateFormatsValue { get; set; }
	private string DateRoundingValue { get; set; }
	private string? DescriptionValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
	private string? IfValue { get; set; }
	private bool? IgnoreFailureValue { get; set; }
	private string? IndexNameFormatValue { get; set; }
	private string? IndexNamePrefixValue { get; set; }
	private string? LocaleValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor>? OnFailureValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor OnFailureDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor> OnFailureDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor>[] OnFailureDescriptorActions { get; set; }
	private string? TagValue { get; set; }
	private string? TimezoneValue { get; set; }

	/// <summary>
	/// <para>An array of the expected date formats for parsing dates / timestamps in the document being preprocessed.<br/>Can be a java time pattern or one of the following formats: ISO8601, UNIX, UNIX_MS, or TAI64N.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor DateFormats(ICollection<string> dateFormats)
	{
		DateFormatsValue = dateFormats;
		return Self;
	}

	/// <summary>
	/// <para>How to round the date when formatting the date into the index name. Valid values are:<br/>`y` (year), `M` (month), `w` (week), `d` (day), `h` (hour), `m` (minute) and `s` (second).<br/>Supports template snippets.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor DateRounding(string dateRounding)
	{
		DateRoundingValue = dateRounding;
		return Self;
	}

	/// <summary>
	/// <para>Description of the processor.<br/>Useful for describing the purpose of the processor or its configuration.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Description(string? description)
	{
		DescriptionValue = description;
		return Self;
	}

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>The field to get the date or timestamp from.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>Conditionally execute the processor.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor If(string? value)
	{
		IfValue = value;
		return Self;
	}

	/// <summary>
	/// <para>Ignore failures for the processor.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor IgnoreFailure(bool? ignoreFailure = true)
	{
		IgnoreFailureValue = ignoreFailure;
		return Self;
	}

	/// <summary>
	/// <para>The format to be used when printing the parsed date into the index name.<br/>A valid java time pattern is expected here.<br/>Supports template snippets.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor IndexNameFormat(string? indexNameFormat)
	{
		IndexNameFormatValue = indexNameFormat;
		return Self;
	}

	/// <summary>
	/// <para>A prefix of the index name to be prepended before the printed date.<br/>Supports template snippets.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor IndexNamePrefix(string? indexNamePrefix)
	{
		IndexNamePrefixValue = indexNamePrefix;
		return Self;
	}

	/// <summary>
	/// <para>The locale to use when parsing the date from the document being preprocessed, relevant when parsing month names or week days.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Locale(string? locale)
	{
		LocaleValue = locale;
		return Self;
	}

	/// <summary>
	/// <para>Handle failures for the processor.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor OnFailure(ICollection<Elastic.Clients.Elasticsearch.Serverless.Ingest.Processor>? onFailure)
	{
		OnFailureDescriptor = null;
		OnFailureDescriptorAction = null;
		OnFailureDescriptorActions = null;
		OnFailureValue = onFailure;
		return Self;
	}

	public DateIndexNameProcessorDescriptor OnFailure(Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor descriptor)
	{
		OnFailureValue = null;
		OnFailureDescriptorAction = null;
		OnFailureDescriptorActions = null;
		OnFailureDescriptor = descriptor;
		return Self;
	}

	public DateIndexNameProcessorDescriptor OnFailure(Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor> configure)
	{
		OnFailureValue = null;
		OnFailureDescriptor = null;
		OnFailureDescriptorActions = null;
		OnFailureDescriptorAction = configure;
		return Self;
	}

	public DateIndexNameProcessorDescriptor OnFailure(params Action<Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor>[] configure)
	{
		OnFailureValue = null;
		OnFailureDescriptor = null;
		OnFailureDescriptorAction = null;
		OnFailureDescriptorActions = configure;
		return Self;
	}

	/// <summary>
	/// <para>Identifier for the processor.<br/>Useful for debugging and metrics.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Tag(string? tag)
	{
		TagValue = tag;
		return Self;
	}

	/// <summary>
	/// <para>The timezone to use when parsing the date and when date math index supports resolves expressions into concrete index names.</para>
	/// </summary>
	public DateIndexNameProcessorDescriptor Timezone(string? timezone)
	{
		TimezoneValue = timezone;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("date_formats");
		JsonSerializer.Serialize(writer, DateFormatsValue, options);
		writer.WritePropertyName("date_rounding");
		writer.WriteStringValue(DateRoundingValue);
		if (!string.IsNullOrEmpty(DescriptionValue))
		{
			writer.WritePropertyName("description");
			writer.WriteStringValue(DescriptionValue);
		}

		writer.WritePropertyName("field");
		JsonSerializer.Serialize(writer, FieldValue, options);
		if (!string.IsNullOrEmpty(IfValue))
		{
			writer.WritePropertyName("if");
			writer.WriteStringValue(IfValue);
		}

		if (IgnoreFailureValue.HasValue)
		{
			writer.WritePropertyName("ignore_failure");
			writer.WriteBooleanValue(IgnoreFailureValue.Value);
		}

		if (!string.IsNullOrEmpty(IndexNameFormatValue))
		{
			writer.WritePropertyName("index_name_format");
			writer.WriteStringValue(IndexNameFormatValue);
		}

		if (!string.IsNullOrEmpty(IndexNamePrefixValue))
		{
			writer.WritePropertyName("index_name_prefix");
			writer.WriteStringValue(IndexNamePrefixValue);
		}

		if (!string.IsNullOrEmpty(LocaleValue))
		{
			writer.WritePropertyName("locale");
			writer.WriteStringValue(LocaleValue);
		}

		if (OnFailureDescriptor is not null)
		{
			writer.WritePropertyName("on_failure");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, OnFailureDescriptor, options);
			writer.WriteEndArray();
		}
		else if (OnFailureDescriptorAction is not null)
		{
			writer.WritePropertyName("on_failure");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor(OnFailureDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (OnFailureDescriptorActions is not null)
		{
			writer.WritePropertyName("on_failure");
			writer.WriteStartArray();
			foreach (var action in OnFailureDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Ingest.ProcessorDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else if (OnFailureValue is not null)
		{
			writer.WritePropertyName("on_failure");
			JsonSerializer.Serialize(writer, OnFailureValue, options);
		}

		if (!string.IsNullOrEmpty(TagValue))
		{
			writer.WritePropertyName("tag");
			writer.WriteStringValue(TagValue);
		}

		if (!string.IsNullOrEmpty(TimezoneValue))
		{
			writer.WritePropertyName("timezone");
			writer.WriteStringValue(TimezoneValue);
		}

		writer.WriteEndObject();
	}
}